//
//  PhotoScrollView.m
//  时光电影项目
//
//  Created by 墨狂之逸才 on 15/7/23.
//  Copyright (c) 2015年 墨狂之逸才. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation PhotoScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        //创建scrollView里面的imageView
        _imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        
        
        self.delegate = self;
        
        //设置放大倍数
        self.maximumZoomScale = 3;
        self.minimumZoomScale = 1;
        
        
        //添加手势
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
        
        //默认为单击
        singleTap.numberOfTapsRequired = 1;
        singleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:singleTap];
        
        //屏蔽双击手势
        [singleTap requireGestureRecognizerToFail:doubleTap];
        
        
        //拿数据可以到layoutSubviews里面去写，
//        _imageUrlStr = 
        [self setNeedsLayout];
        
        [self addSubview:_imageView];
        
        
    }
    return self;
    
}


- (void)doubleTap
{
    NSLog(@"doubleTap");
    
    if (self.zoomScale == 1) {
        [self setZoomScale:3 animated:YES];
    }else
    {
        [self setZoomScale:1 animated:YES];
    }
}

- (void)singleTap
{
    
    NSLog(@"singleTap");
    //添加通知
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hiddenNavgationBar" object:nil];
}


#pragma mark - set方法
- (void)setImageUrlStr:(NSString *)imageUrlStr
{
    _imageUrlStr = imageUrlStr;
    
    [self setNeedsLayout];
    
    
}

 - (void)layoutSubviews
{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrlStr]];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
    return _imageView;
}

@end
